package com.randi.system.domain.dto;

import com.baomidou.mybatisplus.annotation.TableField;
import com.randi.common.xss.Xss;
import com.randi.system.domain.entity.sysNotice.SysNotice;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;
import java.util.List;

@Data
public class NoticeBody {

    @NotBlank(message = "公告类型不能为空")
    @TableField(value = "`notice_type`")
    @ApiModelProperty(value = "公告类型")
    private Integer noticeType;

    @Xss(message = "公告标题不能包含脚本字符")
    @NotBlank(message = "公告标题不能为空")
    @Size(max = 50, message = "公告标题不能超过50个字符")
    @ApiModelProperty(value = "公告标题")
    private String noticeTitle;

    @NotBlank(message = "公告标题不能为空")
    @ApiModelProperty(value = "公告内容")
    private String noticeContent;

    @ApiModelProperty(value = "推送范围", notes = "0:全部用户 1:自定义用户")
    private Integer pushRange;

    @ApiModelProperty(value = "推送用户", notes = "自定义推送用户")
    private List<Long> userIds;

    /**
     * 转换为实体
     *
     * @return SysNotice
     */
    public SysNotice toEntity() {
        SysNotice sysNotice = new SysNotice();
        sysNotice.setNoticeType(this.noticeType);
        sysNotice.setNoticeTitle(this.noticeTitle);
        sysNotice.setNoticeContent(this.noticeContent);
        sysNotice.setPushRange(this.pushRange);
        return sysNotice;
    }

}
